package com.example.xlmkotlinwanandroid.ui.adapter

import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.ImageView
import androidx.recyclerview.widget.RecyclerView
import com.example.xlmkotlinwanandroid.R


class WelcomePageAdapter() :
    RecyclerView.Adapter<WelcomePageAdapter.BaseViewHolder?>() {
    lateinit var itemDatas: List<Int>
    //设置数据
    fun setDatas(itemDatas: List<Int>) {
        this.itemDatas = itemDatas
    }

    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): BaseViewHolder {
        val itemView: View = LayoutInflater.from(parent.context)
            .inflate(R.layout.item_welcome_page, parent, false)
        return BaseViewHolder(itemView)
    }

    override fun onBindViewHolder(holder: BaseViewHolder, position: Int) {
        holder.imageView?.setImageResource(itemDatas.get(position))
//        holder.imageView?.setBackgroundResource(itemDatas.get(position))
    }

    override fun getItemCount(): Int {
        return itemDatas.size
    }

    inner class BaseViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {
        var imageView: ImageView?

        init {
            imageView = itemView.findViewById(R.id.iv_welcome_item)
        }
    }


}